home *** CD-ROM | disk | FTP | other *** search
/ LiquidLibrary 2005 February / LiquidLibrary 2005 February - Disc 1.iso / pc / Portfolio Browser / Filters / PDF / LIB / acc_ps2t.ps next >
Text File  |  2003-01-03  |  21KB  |  577 lines

  1. % Copyright (c) 2001, AccuSoft Corporation.  
  2. % All rights reserved.
  3. %
  4. % This is a PostScript library for sending GhostScript  
  5. % rendering text to stdout stream. The library is used 
  6. % by PDF extension of the ImageGear DLL to extract text 
  7. % from PostScript files.
  8. %
  9. % Created:       09/17/2001 AlexR
  10. % Last modified: 02/12/2002
  11. % Revision:      2
  12. %
  13. % The library redefines show, ashow, widthshow, awidthshow,
  14. % kshow, xshow, yshow and xyshow text rendered operators as 
  15. % procedures to extract text translated to ISOLatin1 encoding.
  16. % The output has following format:
  17. %
  18. %   #S <x0> <y0> <len1> <len2> <string> <x1> <y1> 
  19. %       This line indicates displaying text
  20. %
  21. %   #P   
  22. %       This line indicates the end of the page
  23. % <x0>, <y0>, <x1>, <y1> are an integer coordinates in 1/100 of device units.
  24. % The (<x0>,<y0>) is start point of painted text and (<x1>, <y1>) is end point.
  25. % These two points specify the direction of text and its location.
  26. % The <string> is extracted text that consist of printable characters in ISOLatin1 
  27. % encoding. <len2> is length of <string>. <len1> is a number of glyphs represented
  28. % by <string>. <len2> can be not equal to <len1> (for example the character with
  29. % glyph name /trademark is represented by "^TM").
  30.  
  31. userdict begin
  32.  
  33. % Redefines the operator if it already exists
  34. % Used for redefining standard "show" operators
  35.  
  36. /IG_redef         % name proc IG_redef -
  37. {
  38.   1 index where 
  39.          { pop def } 
  40.          { pop pop } ifelse
  41. } bind def
  42.  
  43. /IG_PStoTxtDict 50 dict def
  44.  
  45. % Declare all names in our private dictionary
  46.  
  47. //IG_PStoTxtDict begin
  48.  
  49. % OT1 encoding. It is used for self-named glyphs of Type 3 fonts. 
  50.  
  51. /_DvipsOT1
  52. [
  53.    % 0
  54.    (\\Gamma) (\\Delta) (\\Theta) (\\Lambda) (\\Xi) (\\Pi) (\\Sigma) (\\Upsilon)
  55.    (\\Phi) (\\Psi) (\\Omega) (ff) (fi) (fl) (ffi) (ffl) (i) (j) (`)
  56.    (') (\237) (\226) (\257) (\232) (\270) (\337) (ae) (oe) (\370) (AE) (OE)
  57.    (\330) (/) (!) ('') (#) ($) (%) (&) (') (\() (\)) (*) (+) (,) (\255) (.) (/)
  58.    (0) (1) (2) (3) (4) (5) (6) (7) (8) (9) (:) (;) (!) (=) (?) (?) (@)
  59.    % 65
  60.    (A) (B) (C) (D) (E) (F) (G) (H) (I) (J) (K) (L) (M) (N) (O) (P) (Q) (R) (S)
  61.    (T) (U) (V) (W) (X) (Y) (Z) 
  62.    % 91
  63.    ([) (``) (]) (^) (_) (`) 
  64.    % 97
  65.    (a) (b) (c) (d) (e) (f) (g) (h) (i) (j) (k) (l) (m) (n) (o) (p) (q) (r) (s) 
  66.    (t) (u) (v) (w) (x) (y) (z) 
  67.    % 123
  68.    (--) (---) (\235) (~) (\250) 
  69. ] def
  70.  
  71.  
  72. % Glyph names used in most True Type encoding vectors (for Type 42 fonts)
  73.  
  74. /_TTGlyphNames1
  75. [
  76.   % 0 gap
  77.   /G00 /G01 /G02 /G03 /G04 /G05 /G06 /G07 /G08 /G09  /G0A /G0B /G0C /G0D /G0E /G0F 
  78.   /G10 /G11 /G12 /G13 /G14 /G15 /G16 /G17 /G18 /G19  /G1A /G1B /G1C /G1D /G1E /G1F 
  79.  
  80.   % 32
  81.   /G20 /G21 /G22 /G23 /G24 /G25 /G26 /G27 /G28 /G29  /G2A /G2B /G2C /G2D /G2E /G2F 
  82.   /G30 /G31 /G32 /G33 /G34 /G35 /G36 /G37 /G38 /G39  /G3A /G3B /G3C /G3D /G3E /G3F 
  83.   /G40 /G41 /G42 /G43 /G44 /G45 /G46 /G47 /G48 /G49  /G4A /G4B /G4C /G4D /G4E /G4F 
  84.   /G50 /G51 /G52 /G53 /G54 /G55 /G56 /G57 /G58 /G59  /G5A /G5B /G5C /G5D /G5E /G5F 
  85.   /G60 /G61 /G62 /G63 /G64 /G65 /G66 /G67 /G68 /G69  /G6A /G6B /G6C /G6D /G6E /G6F 
  86.   /G70 /G71 /G72 /G73 /G74 /G75 /G76 /G77 /G78 /G79  /G7A /G7B /G7C /G7D /G7E 
  87.  
  88.   % 127 
  89.   /G7F 
  90.   /G80 /G81 /G82 /G83 /G84 /G85 /G86 /G87 /G88 /G89  /G8A /G8B /G8C /G8D /G8E /G8F 
  91.  
  92.   % 144
  93.   /G90 /G91 /G92 /G93 /G94 /G95 /G96 /G97 /G98 /G99  /G9A /G9B /G9C /G9D /G9E /G9F 
  94.  
  95.   /GA0 /GA1 /GA2 /GA3 /GA4 /GA5 /GA6 /GA7 /GA8 /GA9 /GAA /GAB /GAC /GAD /GAE /GAF
  96.   /GB0 /GB1 /GB2 /GB3 /GB4 /GB5 /GB6 /GB7 /GB8 /GB9 /GBA /GBB /GBC /GBD /GBE /GBF 
  97.   /GC0 /GC1 /GC2 /GC3 /GC4 /GC5 /GC6 /GC7 /GC8 /GC9 /GCA /GCB /GCC /GCD /GCE /GCF 
  98.   /GD0 /GD1 /GD2 /GD3 /GD4 /GD5 /GD6 /GD7 /GD8 /GD9 /GDA /GDB /GDC /GDD /GDE /GDF
  99.   /GE0 /GE1 /GE2 /GE3 /GE4 /GE5 /GE6 /GE7 /GE8 /GE9 /GEA /GEB /GEC /GED /GEE /GEF 
  100.   /GF0 /GF1 /GF2 /GF3 /GF4 /GF5 /GF6 /GF7 /GF8 /GF9 /GFA /GFB /GFC /GFD /GFE /GFF 
  101. ] def
  102.  
  103. /_TTGlyphNames2
  104. [
  105.   % 0 gap
  106.   /G0  /G1  /G2  /G3  /G4  /G5  /G6  /G7  /G8  /G9   /G0a /G0b /G0c /G0d /G0e /G0f 
  107.   /G10 /G11 /G12 /G13 /G14 /G15 /G16 /G17 /G18 /G19  /G1a /G1b /G1c /G1d /G1e /G1f 
  108.  
  109.   % 32
  110.   /G20 /G21 /G22 /G23 /G24 /G25 /G26 /G27 /G28 /G29  /G2a /G2b /G2c /G2d /G2e /G2f 
  111.   /G30 /G31 /G32 /G33 /G34 /G35 /G36 /G37 /G38 /G39  /G3a /G3b /G3c /G3d /G3e /G3f 
  112.   /G40 /G41 /G42 /G43 /G44 /G45 /G46 /G47 /G48 /G49  /G4a /G4b /G4c /G4d /G4e /G4f 
  113.   /G50 /G51 /G52 /G53 /G54 /G55 /G56 /G57 /G58 /G59  /G5a /G5b /G5c /G5d /G5e /G5f 
  114.   /G60 /G61 /G62 /G63 /G64 /G65 /G66 /G67 /G68 /G69  /G6a /G6b /G6c /G6d /G6e /G6f 
  115.   /G70 /G71 /G72 /G73 /G74 /G75 /G76 /G77 /G78 /G79  /G7a /G7b /G7c /G7d /G7e 
  116.  
  117.   % 127 
  118.   /G7F 
  119.   /G80 /G81 /G82 /G83 /G84 /G85 /G86 /G87 /G88 /G89  /G8a /G8b /G8c /G8d /G8e /G8f 
  120.  
  121.   % 144
  122.   /G90 /G91 /G92 /G93 /G94 /G95 /G96 /G97 /G98 /G99  /G9a /G9b /G9c /G9d /G9e /G9f 
  123.  
  124.   /Ga0 /Ga1 /Ga2 /Ga3 /Ga4 /Ga5 /Ga6 /Ga7 /Ga8 /Ga9 /Gaa /Gab /Gac /Gad /Gae /Gaf
  125.   /Gb0 /Gb1 /Gb2 /Gb3 /Gb4 /Gb5 /Gb6 /Gb7 /Gb8 /Gb9 /Gba /Gbb /Gbc /Gbd /Gbe /Gbf 
  126.   /Gc0 /Gc1 /Gc2 /Gc3 /Gc4 /Gc5 /Gc6 /Gc7 /Gc8 /Gc9 /Gca /Gcb /Gcc /Gcd /Gce /Gcf 
  127.   /Gd0 /Gd1 /Gd2 /Gd3 /Gd4 /Gd5 /Gd6 /Gd7 /Gd8 /Gd9 /Gda /Gdb /Gdc /Gdd /Gde /Gdf
  128.   /Ge0 /Ge1 /Ge2 /Ge3 /Ge4 /Ge5 /Ge6 /Ge7 /Ge8 /Ge9 /Gea /Geb /Gec /Ged /Gee /Gef 
  129.   /Gf0 /Gf1 /Gf2 /Gf3 /Gf4 /Gf5 /Gf6 /Gf7 /Gf8 /Gf9 /Gfa /Gfb /Gfc /Gfd /Gfe /Gff 
  130.   
  131. ] def
  132.  
  133.  
  134. % Translates character into one character string 
  135.  
  136. /_char_to_string           % int _char_to_string str1
  137.                            % int - character code
  138. {
  139.    1 string dup 0 4 -1 roll put
  140. } def 
  141.  
  142.  
  143. % This function juxtaposes glyph names from _TTGlyphNames1 or 
  144. % _TTGlyphNames2 with its string representation. 
  145. % Used for filling of ISOLatin1CharStrings dictionary
  146.  
  147. /_tt_pair_get              % int bool _tt_pair_get name str
  148.  
  149.                            % int - character code that is index of glyph name 
  150.                            % bool - if true the name is taken from _TTGlyphNames1 
  151.                            % array otherwise it is taken from _TTGlyphNames2
  152. {
  153.    {
  154.       dup //_TTGlyphNames1 exch get       % get glyph name
  155.       exch //_char_to_string exec          
  156.    }
  157.    {
  158.       
  159.       dup //_TTGlyphNames2 exch get dup   % int name name
  160.       //_TTGlyphNames1 3 index get        % int name name name1
  161.       eq
  162.       {
  163.          % skip 
  164.          pop pop
  165.       }
  166.       {
  167.          exch //_char_to_string exec 
  168.       }
  169.       ifelse
  170.    }
  171.    ifelse
  172. } def
  173.  
  174. % The first 256 characters of True Type encoding (excluding 130 - 159) coincide
  175. % with ISO1 Latin encoding. 
  176. % Pushes True Type encoding to stack 
  177.  
  178. /_tt_glyph_encode          % bool _tt_glyph1_encode name1 str1 ... namen strn
  179.  
  180.                            % bool - if true the name is taken from _TTGlyphNames1 
  181.                            % array otherwise it is taken from _TTGlyphNames2
  182. {
  183.    /tt_glyph1 exch def
  184.  
  185.    % The first 32 characters is undefined. Skip them
  186.    32 1 127
  187.    {
  188.       tt_glyph1 //_tt_pair_get exec
  189.    } for
  190.    
  191.    % Skip characters 128 - 159
  192.  
  193.    160 1 255
  194.    {
  195.       tt_glyph1 //_tt_pair_get exec
  196.    } for
  197.  
  198. } def
  199.  
  200.  
  201. % Character encoding dictionary.
  202. % The keys are most popular glyph names, the values are strings in ISO Latin1 encoding
  203. % associated with this names.
  204.  
  205. /ISOLatin1CharStrings
  206. <<
  207.    /.notdef ()
  208.  
  209. % 0 - 9
  210.  
  211.    /zero (0) /one (1) /two (2) /three (3) /four (4) /five (5) 
  212.    /six (6) /seven (7) /eight (8) /nine (9)
  213. %  
  214.    /ampersand (&)     /at (@)             /cent (c)           /hyphen (-)
  215.    /space ( )         /comma (,)          /asciicircum (^)    /asciitilde (~) 
  216.    /asterisk (*)      /colon (:)          /period (.)         /periodcentered (\267) 
  217.    /minus (-)         /endash (--)        /emdash (---)       /exclam (!)        
  218.    /fraction (/)      /backslash (\\)     /bar (|)            /braceleft ({) 
  219.    /braceright (})    /bracketleft ([)    /bracketright (])   /brockenbar (|)     
  220.    /dolar ($)         /equal (=)          /greater (>)        /greaterequal (>=) 
  221.    /less (<)          /lessequal (<=)     /numbersign (#)     /parenleft (\()
  222.    /parenright (\))   /percent (%)        /perthousand (o/oo) /plus (+)
  223.    /question (?)      /quotedbl (")       /quotedblbase (,,)  /quotedblleft (``) 
  224.    /quotedblright ('') /quoteleft (`)     /quoteright (')
  225.    /quotesinglbase (') /quotesingle (')   /slash (/)          /semicolon (;)
  226.    /trademark (^TM)   /underscore (_)     /ff (ff)            /fi (fi)
  227.    /ffi (ffi)         /fl (fl)            /ffl (ffl)          /floring (f)
  228.    /second ('')       /minute (')         /daggerdbl (#)
  229.  
  230. % ISO Latin1 special
  231.  
  232.    /acute (\264)      /breve (\226)       /caron (\237)       /circumflex (\223)
  233.    /dieresis (\250)   /dotaccent (\227)   /dotlessi (\220)    /grave (\221)
  234.    /hungarumlaut (\235) /macron (\257)    /ogonek (\236)      /ring  (\232)
  235.    /tilde    (\224)   
  236.  
  237. % Other standard latin characters
  238.  
  239.    /ae (ae)             /AE (AE)            /Aacute (\301)      /Abreve (A\226)   
  240.    /Acircumpflex (\302) /Adieresis (\304)   /Agrave (\300)      /Amacron (A\257)
  241.    /Aogonek (A\236)     /Aring (\305)       /Atilde (\303)      /Cacute (C\264)
  242.    /Ccaron (C\237)      /Ccedilla (\307)    /Dcaron (D\237)     /Dcroat (\320)
  243.    /Eacute (\311)       /Ecaron (E\237)     /Ecircumflex (\312) /Edieresis (\313)
  244.    /Edotaccent (E\227)  /Egrave (\310)      /Emacron (E\257)    /Eogonek (E\236)
  245.    /Eth (\320)          /Gbreve (G\226)     /Gcommaaccent (G,)  /Iacute (\315)
  246.    /Icircumflex (\316)  /Idieresis (\317)   /Idotaccent (I\227) /Igrave (\314)
  247.    /Imacron (I\257)     /Iogonek (I\236)    /Kcommaaccent (K,)  /Lacute (L\264)
  248.    /Lcaron (L\237)      /Lcommaaccent (L,)  /Lslash (L/)        /Nacute (N\234)
  249.    /Ncaron (N\237)      /Ncommaaccent (N,)  /Ntilde (\321)      /OE (OE)
  250.    /Oacute (\323)       /Ocircumflex (\324) /Odieresis (\326)   /Ograve (\322)
  251.    /Ohungarumlaut (O\235)  /Omacron (O\257) /Oslash (\330)      /Otilde (\325)
  252.    /Racute (R\264)      /Rcaron (R\237)     /Rcommaaccent (R,)  /Sacute (S\264)
  253.    /Scaron (S\237)      /Scedilla (S,)      /Scommaaccent (S,)  /Tcaron (T\237)
  254.    /Tcommaaccent (T,)   /Thorn (\336)       /Uacute (\332)      /Ucircumflex (\333)
  255.    /Udieresis (\334)    /Ugrave (\331)      /Uhungarumlaut (U\235) /Umacron (U\257)
  256.    /Uogonek (U\236)     /Uring (U\232)      /Yacute (\335)      /Ydieresis (Z\250)
  257.    /Zacute (Z\264)      /Zcaron (Z\237)     /Zdotaccent (Z\227) /aacute (\341)
  258.    /abreve (a\226)      /acircumflex (\342) /adieresis (\344)   /agrave (\340)
  259.    /amacron (a\257)     /aogonek (a\236)    /aring (\345)       /atilde (\343)
  260.    /bullet (.)          /cacute (c\264)     /ccaron (c\237)     /ccedilla (\347)
  261.    /commaaccent (,)     /copyright (\251)   /currency (\244)    /dcaron (d\237)
  262.    /dcroat (d)          /degree (\260)      /devide (\360)      /eacute (\351)
  263.    /ecaron (e\237)      /ecircumflex (\352) /edieresis (\353)   /edotaccent (e\227)
  264.    /egrave (\350)       /ellipsis (...)     /emacron (e\267)    /eogonek (e\236)
  265.    /eth (\360)          /exclamdown (!)     /dagger (+)         /gbreve (g\226)
  266.    /gcommaaccent (g,)   /germandbls (\337)  /guillemotleft (\253) /guillemotright (\273)
  267.    /guilsinglleft (<)   /guilsinglright (>) /iacute  (\355)     /icircumflex   (\356)
  268.    /idieresis (\357)    /igrave (\354)      /imacron (i\257)    /iogonek (i\236)
  269.    /kcommaaccent (k,)   /lacute (l\264)     /lcaron (l\237)     /lcommaaccent (l,)
  270.    /logicalnot  (\254)  /lslash   (l/)      /mu  (\265)         /multiply (\327)
  271.    /nacute (n\264)      /ncaron (n\237)     /ncommaaccent (n,)  /notequal   (=)
  272.    /ntilde (\361)       /oacute  (\363)     /ocircumflex (\364) /odieresis (\366)
  273.    /oe  (oe)            /ograve (\362)      /ohungarumlaut (o\237) /omacron (o\267)
  274.    /onehalf (1/2)       /onequarter (1/4)   /onesuperior (\271) /ordfeminine (\252)
  275.    /ordmasculine (\272) /oslash  (\370)     /otilde (\365)      /paragraph (\266)
  276.    /partialdiff (d)     /plusminus (\261)   /questiondown (?)   /racute (\162)
  277.    /rcaron (r\237)      /rcommaaccent (r,)  /registered (\256)  /sacute (s\264)
  278.    /scaron (s\237)      /scedilla (s,)      /scommaaccent (s,)  /section (\247)
  279.    /sterling (\243)     /tcaron (t\237)     /tcommaaccent (t,)  /thorn (\376)
  280.    /threequarter (3/4)  /threesuperior (\263) /twosuperior (\262) /uacute (\372)
  281.    /ucircumflex (\373)  /udieresis (\374)   /ugrave (\371)      /uhungarumlaut (u\237)
  282.    /umacron (u\257)     /uogonek (u\236)    /uring (u\232)      /yacute (\375)
  283.    /ydieresis (\377)    /yen (\245)         /zacute (z\264)     /zcaron (z\237)
  284.    /zdotaccent (z\227)
  285.    
  286. % Some characters from Symbol Encoding
  287.  
  288.    /Alpha (A)           /Beta (B)           /Chi (X)            /Delta (\\Delta)
  289.    /Epsilon (E)         /Eta (H)            /Euro (C)           /Gamma (\\Gamma)
  290.    /Ifraktur (J)        /Iota (I)           /Kappa (K)          /Lambda (\\Lambda)
  291.    /Mu (M)              /Nu (N)             /Omega (O)          /Omicron (O)
  292.    /Phi (\\Phi)         /Pi (\\Pi)          /Psi (\\Psi)        /Rfraktur (R)
  293.    /Rho (P)             /Sigma (\\Sigma)    /Tau (T)            /Theta (\\Theta)
  294.    /Upsilon (Y)         /Upsilon1 (Y)       /Xi  (\\Xi)         /Zeta (Z)
  295.    /aleph (x)           /alpha (a)          /angleleft (<)      /angleright (>)
  296.    /approxequal (=)     /asteriskmath (*)   /chi (X)            /copyrightsans (\(C\))
  297.    /copyrightserif (\(C\)) /delta (\\delta) /dotmath (.)        /element (c)
  298.    /equivalence (=)     /eta (n)            /gamma (\\gamma)    /iota (i)
  299.    /kappa (k)           /lambda (\lambda)   /logicaland (^)     /logicalor (V)
  300.    /omicron (o)         /phi (\\phi)        /phi1 (\\phi)       /pi (\\pi)
  301.    /psi (\\psi)         /registersans (\(R\))   /registerserif (\(R\))
  302.    /rho (p)             /sigma (o)          /sigma1 (c)         /tau (t)
  303.    /theta (\\theta)     /theta1 (\\theta)   /trademarksans (^TM) /trademarkserif (^TM)
  304.  
  305. % self-named glyphs OT1 encoding including letters A - Z, a - z
  306.  
  307.    0 1 127
  308.    {
  309.      dup //_char_to_string exec cvn _DvipsOT1 3 -1 roll get 
  310.    } for
  311.  
  312. % number-named glyph names
  313.  
  314.    0 1 127
  315.    {
  316.      dup 10 3 string cvrs cvn _DvipsOT1 3 -1 roll get 
  317.    } for
  318.  
  319. % True Type encoding 
  320.    
  321.    true //_tt_glyph_encode exec
  322.    false //_tt_glyph_encode exec
  323.  
  324. % True Type from 130 to 159
  325.    /G82 (')    /G83 (f)      /G84 ('')    /G85 (...)  /G86 (+)  /G87 (#)   /G88 (\223)
  326.    /G89 (o/oo) /G8A (S\237)  /G8B (<)     /G8C (OE)   /G91 (`)  /G92 (')   /G93 (``)
  327.    /G94 ('')   /G95 (.)      /G96 (--)    /G97 (---)  /G98 (~)  /G99 (^TM) /G9A (s\237)
  328.    /G9B (>)    /G9C (oe)     /G9F (Y\250) 
  329.    
  330.    /G8a (S\237)  /G8b (<)  /G8c (OE)  /G9a (s\237)  /G9b (>)  /G9c (oe)  /G9f (Y\250) 
  331.  
  332. >> def
  333.  
  334.  
  335. % Converts integer into string and writes it to stdout
  336. /_int_output         % int _int_output -  
  337. {
  338.    20 string cvs print 
  339. } def
  340.  
  341.  
  342. % Transforms point (x,y) into output coordinates 
  343. /_to_output_coord             % x y _to_output_coord x' y'
  344. {
  345.    transform
  346.    
  347.    100 mul 
  348.    round cvi          
  349.    exch 
  350.    100 mul 
  351.    round cvi     
  352.    exch  
  353. } def
  354.  
  355.  
  356. % Writes current point into stdout
  357. /_print_current_location      % - _print_current_location -
  358. {
  359.    currentpoint               % stack: x y  
  360.    //_to_output_coord exec    % stack: x' y'  
  361.  
  362.    exch
  363.    //_int_output exec         % print x'
  364.    ( ) print
  365.    //_int_output exec         % print y'
  366.    ( ) print
  367. } def
  368.  
  369. % Replace all string character by ISO Latin1 equivalent
  370. % according to ISOLatin1CharStrings dictionary
  371.  
  372. /_output_string_get           % str _print_string str2 str2Length
  373. {
  374. //userdict /IG_PStoTxtDict get 
  375. begin
  376.  
  377.    /outString () def
  378.    /outWidth  0 def
  379.    
  380.    {   
  381.       dup                                 % stack: ch ch   
  382.  
  383.    % Get the glyph name
  384.       currentfont /Encoding get exch get  % stack: ch name   
  385.       
  386.       ISOLatin1CharStrings exch 2 copy    % stack: ch ISOLatin1CharStrings name ISOLatin1CharStrings name
  387.       known
  388.       {                                   % stack: ch ISOLatin1CharStrings name
  389.         get                               % stack: ch str1 
  390.         exch pop                          % stack: str1
  391.       }
  392.    % undefined in ISOLatin1CharStrings name
  393.       {                                   % stack: ch ISOLatin1CharStrings name
  394.          pop pop                          % stack: ch
  395.  
  396.          dup dup 32 ge exch 126 le and 
  397.          {
  398.             % Try to get ascii character.
  399.             % For some fonts it is wrong but 
  400.             % usually we will get right results
  401.  
  402.             1 string dup            % stack: ch str str
  403.             0 4 -1 roll             % stack: str str 0 ch
  404.             put                     % stack: str1
  405.          }
  406.          {
  407.             % we cannot say anything about this character
  408.             pop
  409.             (#)
  410.          }
  411.          ifelse
  412.  
  413.       }
  414.       ifelse     
  415.          
  416.       % put to result string 
  417.        
  418.       dup length outWidth add string dup dup    % stack: str1 str str str
  419.       0 outString putinterval                   % stack: str1 outString_ outString_
  420.       outWidth 4 -1 roll putinterval            % stack: outString_str1
  421.       /outString exch def
  422.       /outWidth  outString length def
  423.  
  424.    } forall
  425.  
  426.    outString
  427.    outWidth
  428.  
  429. end % IG_PStoTxtDict
  430. } def
  431.  
  432. % Writes #S directive into stdout
  433.  
  434. /IG_output_make   % ... string proc IG_output_make -
  435.                   % proc - is operator that shows the string
  436. {
  437. //userdict /IG_PStoTxtDict get 
  438. begin
  439.    
  440.    1 index
  441.    dup () eq
  442.    {                                % stack: ... string proc string   
  443.       % draw text to change current point
  444.       pop
  445.       exec   
  446.    }
  447.    {                                % stack: ... string proc string
  448.       (#S ) print
  449.    
  450.       % print string start location
  451.       _print_current_location       % stack: ... string proc string
  452.    
  453.       dup                           % stack: ... string proc string string  
  454.  
  455.       % print glyphs count
  456.       length _int_output            % stack: ... string proc string
  457.  
  458.       ( ) print
  459.       
  460.       % get the string in ISO Latin1 encoding and its length
  461.  
  462.       _output_string_get            % stack: ... string proc str strLength     
  463.  
  464.       % print output string length
  465.  
  466.       _int_output                   % stack: ... string proc str     
  467.  
  468.       ( ) print
  469.  
  470.       % print text
  471.  
  472.       print                         % stack: ... string proc     
  473.       ( ) print
  474.  
  475.       % draw text to change current point
  476.       exec                          % stack: -
  477.  
  478.       % print string end location
  479.       _print_current_location       
  480.  
  481.       (\n) print
  482.    } ifelse
  483.  
  484. end % IG_PStoTxtDict
  485. } def
  486.  
  487. end %IG_PStoTxtDict begin
  488.  
  489. % Redefine the end-of-page operators.
  490.  
  491. /copypage 
  492.    (\n) print
  493.    (#P\n) print
  494.    (\n) print 
  495. } bind IG_redef
  496.  
  497. /showpage 
  498.    //userdict /copypage get exec 
  499.    initgraphics 
  500. } bind IG_redef
  501.  
  502. % Redefine "show" operators to extract text
  503. /show 
  504. {
  505.    //systemdict /show get 
  506.    //userdict /IG_PStoTxtDict get /IG_output_make get exec 
  507. } bind IG_redef
  508.  
  509. /ashow 
  510. {
  511.    //systemdict /ashow get 
  512.    //userdict /IG_PStoTxtDict get /IG_output_make get exec   
  513. } bind IG_redef
  514.  
  515. /widthshow 
  516. {
  517.    //systemdict /widthshow get 
  518.    //userdict /IG_PStoTxtDict get /IG_output_make get exec 
  519. } bind IG_redef
  520.  
  521. /awidthshow 
  522. {
  523.    //systemdict /awidthshow get 
  524.    //userdict /IG_PStoTxtDict get /IG_output_make get exec
  525. } bind IG_redef
  526.  
  527. /kshow 
  528. {
  529. //userdict /IG_PStoTxtDict get
  530. begin
  531.                                           % stack: proc str
  532.    dup                                    % stack: proc str str
  533.    /str_length exch length def            % stack: proc str
  534.  
  535.    {                                      % stack: proc ch
  536.       /str_length str_length 1 sub def
  537.       
  538.       _char_to_string                     % stack: proc str1
  539.       //userdict /show get exec           % stack: proc 
  540.  
  541.       str_length 0 gt
  542.       {                                   
  543.          dup exec                         % stack: proc       
  544.       } if
  545.    } forall 
  546.  
  547. end % IG_PStoTxtDict                      % stack: proc       
  548.  
  549.    pop
  550. } bind IG_redef
  551.  
  552. /xshow 
  553. {
  554.    pop //userdict /show get exec 
  555. } bind IG_redef
  556.  
  557. /yshow 
  558. {
  559.    pop //userdict /show get exec
  560. } bind IG_redef
  561.  
  562. /xyshow 
  563. {
  564.    pop //userdict /show get exec
  565. } bind IG_redef
  566.  
  567. end  % userdict begin
  568.  
  569.  
  570. systemdict begin .bindoperators end 
  571.  
  572. /bind /.bind load def 
  573.  
  574. systemdict readonly pop
  575.